package approve.action;

import java.util.ArrayList;

import nguyen.dao.DatabaseDAO;

import model.pojo.AcEliManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class AndroidApprovalActivity extends Activity {
	private ArrayList<AcEliManager> array;
	public ArrayList<AcEliManager> getArray() {
		return array;
	}
	public void setArray(ArrayList<AcEliManager> array) {
		this.array = array;
	}
	ListView list;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        loadList();
    }
    private void loadList(){
    	ArrayAdapter<String> listType = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataName());
    	list  = (ListView)findViewById(R.id.listDatabase);
    	list.setAdapter(listType);
    	list.setOnItemClickListener(selectItem);
    }
    private ArrayList<String> dataName(){
    	DatabaseDAO dao = new DatabaseDAO();
    	array = dao.getAllCompanyList();
    	ArrayList<String> name = new ArrayList<String>();
    	for (AcEliManager ace : array) {
			if(!ace.getDatabaseName().equals("admin")){
				name.add(ace.getPartnerName());
			}
		}
    	return name;
    }
    private OnItemClickListener selectItem = new OnItemClickListener() {


		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			String name = arg0.getItemAtPosition(arg2).toString();
			for (AcEliManager ace : array) {
				if(ace.getPartnerName().equals(name)){
					Intent it = new Intent(AndroidApprovalActivity.this,LoginActivity.class);
					it.putExtra("database", ace.getDatabaseName());
					startActivityForResult(it, 0);
				}
			}
		}
    	
	};
}